/**
 * Created by IntelliJ IDEA.
 * User: terminator
 * Date: 8/23/11
 * Time: 11:38 AM
 * To change this template use File | Settings | File Templates.
 */
(function(){
    	function removeAny(arr,index){
			for(var i=index;i<arr.length-1;i++){
				arr[i]=arr[i+1];
			}
			arr.length=arr.length-1;
		}
		/*定义除了all这个复选框之外的复选框的点击响应事件*/
		var inputList=document.getElementsByTagName('input'),length=inputList.length;
		var selected=[];
		for(var i=0;i<length;i++){
			if(inputList.value!="all"){
				inputList[i].onclick=function(){
					if(this.checked){
						selected.push(this.value);
					}else{
						for(var i=0;i<selected.length;i++){
							if(selected[i]==this.value){
								removeAny(selected,i);
							}
						}
					}
					alert(selected);
				}
			}
		}
		document.getElementById("all").onclick=function(){
			if(this.checked){
				for(var i=0;i<length;i++){
					for(var j=0;j<selected.length;j++){
						if(inputList[i].value!="all"&&selected[j]==inputList[i].value){
							inputList[i].checked=false;
						}
					}
				}
				for(var k=0;k<length;k++){
					if(inputList[k].value!="all"){
						inputList[k].disabled=true;
					}
				}
			}
			else{
				for(var k=0;k<length;k++){
					inputList[k].disabled=false;
				}
				for(var i=0;i<length;i++){
					for(var j=0;j<selected.length;j++){
						if(inputList[i].value!="all"&&selected[j]==inputList[i].value){
							inputList[i].checked=true;
						}
					}
				}
			}
		};
})();